package com.whale.cloud.util.jdbc;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

/**
 * Created by xdl on 2017/5/25.
 * JDBC配置信息
 */
@Configuration
@ConditionalOnClass(JdbcClient.class)
public class JdbcAutoConfiguration {

    @Autowired
    @Qualifier("primaryDataSource")
    DataSource primaryDataSource;

    @Autowired
    @Qualifier("secondaryDataSource")
    DataSource secondaryDataSource;


    @Autowired
    @Qualifier("primaryJdbcTemplate")
    JdbcTemplate jdbcTemplateConfig1;

    @Autowired
    @Qualifier("secondaryJdbcTemplate")
    JdbcTemplate jdbcTemplateConfig2;




    @Bean(name = "primaryJdbcClient")
    public JdbcClient getJdbcClient1() {
        JdbcClient jdbcClient = new JdbcClient();
        jdbcClient.setJdbcTemplate(primaryDataSource);
        return jdbcClient;
    }

    @Bean(name = "secondaryJdbcClient")
    public JdbcClient getJdbcClient2() {
        JdbcClient jdbcClient = new JdbcClient();
        jdbcClient.setJdbcTemplate(secondaryDataSource);
        return jdbcClient;
    }
}
